{include_core file="lib/header.html" title="选择支付方式"}
<div class="content">
  <br><br>
  <div class="container">
    <!--start:订单支付-->
    <ul class="order-steps clearfix">
      <li class="curr">
        <h4>提交订单</h4>
        <em></em>
      </li>
      <li class="curr">
        <h4>买家支付</h4>
        <em></em>
      </li>
      <li>
        <h4>卖家发货</h4>
        <em></em>
      </li>
      <li>
        <h4>确认收货</h4>
        <em></em>
      </li>
      <li class="last">
        <h4>评价</h4>
        <em></em>
      </li>
    </ul>
    <div class="order-pay-top"></div>
    <div class="order-pay clearfix">
     <div class="pic left" style="min-height:160px;">
       {if $goods_count == 1}
         <a href='{AnUrl("goods/$order_goods_ids[0]")}'><img src="{_image($order_cover_list[0])}"></a>
       {else}
         {$width = 70}
         {foreach $order_goods_ids as $k=>$v}
         <a class="left" href='{AnUrl("goods/$order_goods_ids.$k")}'><img src="{_image($order_cover_list.$k)}" style="max-width:{$width}px;"></a>
         {/foreach}
       {/if}
     </div>
     <div class="pay-detail left">
       <h3><em></em>您的订单已提交成功！</h3>
       <dl class="clearfix">
         <dt>商品名称</dt>
         <dd>
         {if $goods_count == 1}
           {mb_substr($order_title_list[0], 0, 40, 'utf-8')}
         {else}
            {foreach $order_goods_ids as $k=>$v}
            {mb_substr($order_title_list[$k], 0, 40, 'utf-8')}
            {if ($k+1) == $goods_count}等{else}、{/if}
            {/foreach}
         {/if}
         </dd>
       </dl>
       <dl class="clearfix">
         <dt>商品数量</dt>
         <dd>{$order_goods_num}</dd>
       </dl>
       <dl class="clearfix">
         <dt>商品价格</dt>
         <dd>￥{$order_price_total|number_format:2}</dd>
       </dl>
       <dl class="clearfix">
         <dt>订单号</dt>
         <dd>{order_helper::order_id_encode($order_id)}</dd>
       </dl>
       <dl class="clearfix">
         <dt>成交时间</dt>
         <dd>{substr($order_info.add_time, 0, 10)}</dd>
       </dl>
     </div>
    </div>
    <div class="order-pay-addr">
      配送：{$order_info.receivers}/
      {substr($order_info.phone, 0, 3)}*****{substr($order_info.phone, -3)}/
      {$order_info.province} {$order_info.city} {$order_info.district} {$order_info.address}/
      {if $order_info.invoice_title}{$order_info.invoice_title}{else}无发票{/if}
    </div>
    <div class="order-pay-title">选择支付方式</div>
    <ul class="order-pay-types clearfix">
      <li><label><input type="radio" class="js_sltPayMethod" name="pay_method" value="alipay" checked="checked"><img src="../images/img1.png"></label></li>
      <li><label><input type="radio" class="js_sltPayMethod" name="pay_method" value="quickpay"><img src="../images/img2.png"></label></li>
    </ul>
    <div class="clearfix">
      <a href="javascript:void(0);" class="cart-submit right js_payOrder">下一步</a>
      <!-- <a href="javascript:void(0);" class="cart-submit margin-r15 right">修改订单</a> -->
    </div>
    <form action="{AnUrl('openapi/alipay/index/pay')}" method="post" class="js_alipayForm" target="_blank">
      <input type="hidden" class="js_payOrderId" name="order_code"   value="{order_helper::order_id_encode($order_id)}" />
      <input type="hidden" class="js_payMethod"  name="pay_method" value="alipay" />
    </form>
    <form action="{AnUrl('openapi/quickpay/pay')}" method="post" class="js_quickpayForm" target="_blank">
      <input type="hidden" class="js_payOrderId" name="order_code"   value="{order_helper::order_id_encode($order_id)}" />
      <input type="hidden" class="js_payMethod"  name="pay_method" value="quickpay" />
    </form>
    <!--end:订单支付-->
  </div>
</div>
<script>
$(function(){
  // 选择支付方式
  var payMethod = 'alipay';
  $('.js_sltPayMethod').click(function(){
    payMethod = $(this).val();
  });

  // 支付
  $('.js_payOrder').click(function(e){
    var orderId   = $('.js_payOrderId').val();
    if (!orderId) {
      showMsg('当前订单不存在，请重新提交订单！');
      return;
    }
    if (!payMethod) {
      showMsg('请选择支付方式');
      return;
    }

    if (payMethod == 'alipay') {
      $('.js_alipayForm').submit();
    } else {
      $('.js_quickpayForm').submit();
    }

    payConfirm('请您在新打开的网上银行页面进行支付，支付完成前请不要关闭该窗口。', 0, function(){

    });
  });
});
var onceShow = 0;
function payConfirm(msg, showMask, callBackAllowFn) {
  onceShow++;
  if (onceShow > 1) {
    return;
  }
  var confirmBox = document.createElement('div');
  confirmBox.className = 'float-box float-prompt';
  confirmBox.innerHTML = '<a href="javascript:void(0);" id="js_btnClose" class="float-close" title="关闭"></a>\
                        <div class="float-m"><div class="txt">'+msg+'</div></div>\
                        <div class="float-b clearfix">\
                          <a href="javascript:void(0);" id="js_btnAllow" class="float-prompt-btn">已完成支付</a>\
                        </div>';
  confirmBox.style.top = '-1000px';
  confirmBox.style.zIndex="20000";
  document.body.appendChild(confirmBox);

  var bool = 0;
  var rm = function(){
        document.body.removeChild(confirmBox);
        if (showMaskBox) {
          document.body.removeChild(showMaskBox);
        }
        if (bool ==1) {
          if(callBackAllowFn){
            callBackAllowFn();
          }
        } else {
          if(callBackCancelFn){
            callBackCancelFn();
          }
        }
  };

  var allowBtn = document.getElementById('js_btnAllow');
  allowBtn.onclick = function(){
    location.href = siteUrl + "/order";
    bool = 1;
    onceShow = 0;
    rm();
  }

  var closeBtn = document.getElementById('js_btnClose');
  closeBtn.onclick = function(){
    bool = 0;
    onceShow = 0;
    rm();
  }

  var rect = confirmBox.getBoundingClientRect();
  var objWidth = rect.right - rect.left;
  var objheight = rect.bottom - rect.top;
  var offsetLeft = ((getViewportWidth() -20) - objWidth) / 2;
  var offsetTop  = ((getViewportHeight() -20) - objheight) / 2;
  if (offsetTop < 0) {
    offsetTop = 0;
  }
  confirmBox.style.left = offsetLeft +'px';
  confirmBox.style.top = offsetTop+'px';
  confirmBox.style.marginLeft = '0';
  confirmBox.style.marginTop = '0';
}
</script>
{include_core file="lib/footer.html"}